package com.blog.mapper;

import com.blog.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FollowMapper {
    @Select("SELECT id, username, image FROM user WHERE id IN (SELECT user_id FROM follow WHERE follower_id = #{id})")
    List<User> listFocusById(int id);

    @Select("SELECT id, username, image FROM user WHERE id IN (SELECT follower_id FROM follow WHERE user_id = #{id})")
    List<User> listFollowsById(int id);

    @Insert("INSERT INTO follow(user_id, follower_id) VALUES (#{userId}, #{id})")
    void insertFollow(Integer userId, int id);

    @Delete("DELETE FROM follow WHERE user_id = #{userId} AND follower_id = #{id}")
    void deleteFollow(Integer userId, int id);
}
